//
//  ConsultationArrayController.m
//  Cabinet
//
//  Created by Florent Montsegur on 01/11/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ConsultationArrayController.h"
#import "Consultation.h"

@implementation ConsultationArrayController

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    
    return self;
}

- (void)awakeFromNib  
{  
    NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"CreationDate" ascending:NO];
    [self setSortDescriptors:[NSArray arrayWithObject:sort]]; 
    
    [super awakeFromNib];  
}

- (void) setPayement:(NSString*)mode with:(int)state
{
    NSArray *tab = [self selectedObjects];
    if ( (tab== nil) || ([tab count] <= 0 ))
        return;
    
    Consultation * cons = [tab objectAtIndex:0];
    if(cons == nil)
        return;
    
    [cons setPayement:mode];
    [cons setPaye:[NSNumber numberWithInt:state]];
}

- (IBAction)chequeAction:sender
{
    [self setPayement:@"Cheque" with:1];
}

- (IBAction)especesAction:sender
{
    [self setPayement:@"Especes" with:1];
}

- (IBAction)aldAction:sender
{
    [self setPayement:@"ALD" with:0];
}

- (IBAction)cmuAction:sender
{
    [self setPayement:@"CMU" with:0];
}

- (IBAction)atAction:sender
{
    [self setPayement:@"AT" with:0];
}

- (IBAction)artAction:sender
{
    [self setPayement:@"Art 115" with:0];
}

@end
